package cn.cmcc.intertelecom.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.cmcc.intertelecom.bean.Msg;
import cn.cmcc.intertelecom.bean.RoleGroup;
import cn.cmcc.intertelecom.service.RoleGroupService;
import cn.cmcc.intertelecom.utils.ArchivesLog;

@Controller
public class RoleGroupController {
	@Autowired
	private RoleGroupService roleGroupService;
	
	/**
	 * 根据用户的id获取 其角色
	 * @param userId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/roleGroup/{userId}",method=RequestMethod.GET)
	public Msg getRoleByUserId(@PathVariable("userId")Integer userId){
		//System.out.println(userId);
		List<RoleGroup> list=roleGroupService.getRoleByUserId(userId);
		return  Msg.success().add("list", list);
		
	}
	
	/**
	 * 保存用户id和角色id 在roleGroup  也就是建立表与角色的关系
	 * @param userId
	 * @return
	 */
	
	@ArchivesLog(operationPower="update_user_role")
	@ResponseBody
	@RequestMapping(value="/roleGroup",method=RequestMethod.PUT)
	public Msg saveUserRole(RoleGroup roleGroup){
		//System.out.println(roleGroup);
		roleGroupService.saveUserRole(roleGroup);
		return  Msg.success();
		
	}
}
